//
//  ICMRequest.m
//  ICrEAM
//
//  Created by rainimute on 16/11/1.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMRequest.h"

@interface ICMRequest ()

@property (nonatomic, strong) NSDictionary *parameters;

@property (nonatomic, copy) NSString *url;

@end

@implementation ICMRequest

- (instancetype)initWithURL:(NSString *)url andParameters:(NSDictionary *)parameters{
    if (self = [super init]) {
        self.url = url;
        self.parameters = parameters;
    }
    return self;
}

/**请求方式**/
- (YTKRequestMethod)requestMethod{
    return YTKRequestMethodPost;
}

/**接口连接**/
- (NSString *)requestUrl{
    return self.url;
}

/**传入参数**/
- (id)requestArgument{
    
    return self.parameters;
}

- (NSURLRequest *)buildCustomUrlRequest {
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.requestUrl]];
    if (self.requestArgument) {
        [request setHTTPMethod:@"POST"];
        [request addValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
        NSData *rawData = [NSJSONSerialization dataWithJSONObject:self.requestArgument?:@{@"":@""} options:NSJSONWritingPrettyPrinted error:nil];
        [request setHTTPBody:rawData];
    }
    return request;
}


/*header部分*/
- (NSDictionary *)requestHeaderFieldValueDictionary{
    return @{@"Content-Type":@"application/json;charset=UTF-8"};
}

@end








